package com.zhida.smartcontrol.pop;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jay.tools.base.BasePopWindow;
import com.jay.tools.recycler.OnItemClick;
import com.jay.tools.recycler.decoration.RecyclerViewItemDecoration;
import com.jay.tools.utils.DimenUtils;
import com.jay.tools.utils.ResUtil;
import com.zhida.smartcontrol.R;
import com.zhida.smartcontrol.pop.adapter.GroupAdapter;

import java.util.ArrayList;
import java.util.List;

public class GroupPop extends BasePopWindow {
    private RecyclerView mRView;
    private GroupAdapter mAdapter;

    public GroupPop(Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.pop_layout_recycler;
    }

    @Override
    protected void initViews(View v) {
        setWidth(DimenUtils.dp2px(mContext, 70));

        mRView = v.findViewById(R.id.recycler_view);
        mRView.setLayoutManager(new LinearLayoutManager(mContext));
        mRView.addItemDecoration(new RecyclerViewItemDecoration.Builder(mContext)
                .thickness(DimenUtils.dp2px(mContext, 0.48f))
                .color(ResUtil.getColor(mContext, R.color.c_EEEEEE))
                .create());
    }

    @Override
    protected void initData() {
        List<String> data = new ArrayList<>();
        data.add("编辑");
        data.add("删除");
        mAdapter = new GroupAdapter(data);
        mAdapter.bindToRecyclerView(mRView);
    }

    @Override
    protected void initEvents() {
        mAdapter.setClickListener(new OnItemClick<String>() {
            @Override
            public void onClick(String info, int tag) {
                if (null != mListener) {
                    mListener.onClick(info, tag);
                    dismiss();
                }
            }
        });
    }

    @Override
    protected int setCustomHeight() {
        return ViewGroup.LayoutParams.WRAP_CONTENT;
    }
}
